﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WpfApplication1;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        HostsHandler handler;
        CheckBox[] checkBoxes;
        bool bloqueado = false;
        String[] paginas = { "tuenti.com", "twitter.com", "facebook.com", "youtube.com", "seriesyonkis.com", "peliculasyonkis.com", "cinetube.com", "megavideo.com" };
        private void Form1_Load(object sender, EventArgs e)
        {
            checkBoxes = new CheckBox[8];
            checkBoxes[0] = tuentiBox;
            checkBoxes[1] = twitterBox;
            checkBoxes[2] = facebookBox;
            checkBoxes[3] = youtubeBox;
            checkBoxes[4] = syBox;
            checkBoxes[5] = pyBox;
            checkBoxes[6] = cinetubeBox;
            checkBoxes[7] = megavideoBox;
            handler = new HostsHandler();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < checkBoxes.Length; i++)
            {
                if (checkBoxes[i].Checked == true)
                {
                    handler.fuckHost(paginas[i]);
                }
                checkBoxes[i].Enabled = false;
            }
            bloqueado = true;
            this.Text = "Procrastinatio - Páginas bloqueadas";
            MessageBox.Show("La ventana se esconderá en la barra de tareas (lo que está abajo a la derecha del monitor que hay muchos iconos)");
            this.Hide();
            notifyIcon1.Visible = true;
        }
        private void limpiar()
        {
            for (int i = 0; i < checkBoxes.Length; i++)
            {
                if (checkBoxes[i].Checked == true)
                {
                    handler.fixHost(paginas[i]);
                }
                checkBoxes[i].Enabled = true;
            }
            bloqueado = false;
            this.Text = "Procrastinatio";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            limpiar();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (bloqueado)
            {
                MessageBox.Show("Se desbloquearan las paginas");
                limpiar();
            }
        }

        private void todasBox_CheckedChanged(object sender, EventArgs e)
        {
            if (todasBox.Checked == true)
            {
                foreach (CheckBox cb in checkBoxes)
                {
                    cb.Checked = true;
                }
            }
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
            notifyIcon1.Visible = false;
        }
 
    }
}
